#ifndef __COMPONENT_ATTACKER_H__
#define __COMPONENT_ATTACKER_H__

#include "Component.hpp"
#include "Engine/Vector3.hpp"
#include "Engine/Quaternion.h"
#include "Game/IInventory.hpp"
#include "Game/CellFace.h"
#include "Game/TerrainRaycastResult.hpp"
#include "entt/entt.hpp"
#include "Game/RaycastData.h"
#include "GameEnum.h"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    struct ComponentBody;
    struct ComponentMiner;

    class SubsystemTimeOfDay;

    struct ComponentAttacker : public Component
    {
        // 攻击力
        float attackPower;
        // 上次攻击的时间
        double lastHitTime = 0;

        ComponentMiner *componentMiner = nullptr;
        ComponentBody *componentBody = nullptr;

        SubsystemTimeOfDay *timeOfDay = nullptr;

        /**
         * @brief 攻击处理
         * @param target 被攻击的目标
         * @param attacker 攻击者
         * @param hitPosition 攻击的位置
         * @param hitDirection 攻击的方向
         * @param attackPower 攻击的攻击力
         * @param isMeleeAttack 是否是近战攻击
        */
        static void AttackBody(ComponentBody *target, entt::entity attacker, const Vector3 &hitPosition, const Vector3 &hitDirection, float attackPower, bool isMeleeAttack);
        
        /**
         * @brief 打击对应的实体
         * @param entity 打击的实体
         * @param hitPosition 打击的位置
         * @param hitDirection 打击的方向
         * @note 被打击得实体必须有 ComponentBody 组件才有效
        */
        virtual void hit(entt::entity entity, const Vector3 &hitPosition, const Vector3 &hitDirection);

        virtual void hitBody(ComponentBody *body, const Vector3 &hitPosition, const Vector3 &hitDirection);

        RaycastData raycast(const Ray3 &ray, RaycastMode mode);

        virtual const std::string &getName() const override;
        static const std::string &GetName();
        virtual void load(const nlohmann::json &jsonData) override;
    };
    
}

#endif